package com.example.administrator.zhongyichou.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.zhongyichou.R;

/**
 * Created by lichenyu on 2017/12/1.
 * 描述：
 */

public class MyDialog extends Dialog implements View.OnClickListener {
    TextView txtTitle;
    TextView txtContent;
    TextView txtCancel;
    TextView txtConfirm;
    private OnChekedClick onChekedClick;

    public MyDialog(@NonNull Context context) {
        this(context, 0);
    }

    public MyDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, R.style.dialog);
        View view = LayoutInflater.from(context).inflate(R.layout.my_dialog, null);
        setContentView(view);
        txtTitle = (TextView) view.findViewById(R.id.txt_title);
        txtContent = (TextView) view.findViewById(R.id.txt_content);
        txtCancel = (TextView) view.findViewById(R.id.txt_cancel);
        txtConfirm = (TextView) view.findViewById(R.id.txt_confirm);
        txtCancel.setOnClickListener(this);
        txtConfirm.setOnClickListener(this);
    }

    public void setTxtTitle(String title) {
        txtTitle.setText(title);
    }

    public void setTxtContent(String content) {
        txtContent.setText(content);
    }

    public void setTxtCancel(String text) {
        txtCancel.setText(text);
    }

    public void setTxtConfirm(String text) {
        txtConfirm.setText(text);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.txt_cancel:
                onChekedClick.onCancelClick();
                dismiss();
                break;
            case R.id.txt_confirm:
                onChekedClick.onConfirmClick();
                dismiss();
                break;
        }
    }

    public interface OnChekedClick {
        void onCancelClick();

        void onConfirmClick();
    }

    public void setOnChekedClick(OnChekedClick onChekedClick) {
        this.onChekedClick = onChekedClick;
    }
}
